package com.lxx.modules.sys.biz.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.lxx.common.BaseServiceImpl;
import com.lxx.modules.sys.biz.ISysRoleBiz;
import com.lxx.modules.sys.dao.SysRoleDao;
import com.lxx.modules.sys.entity.SysRole;
import com.lxx.vo.UserRoleData;

@Service
public class SysRoleBizImpl extends BaseServiceImpl<SysRole, Integer, SysRoleDao> implements ISysRoleBiz{

	@Override
	public Integer convertId(String idStr) {
		return Integer.parseInt(idStr);
	}

	@Override
	public int delete(SysRole t) {
		t.setDelFlag(true);
		return baseMapper.updateByPrimaryKeySelective(t);
	}

	@Override
	public List<UserRoleData> getUserRoleData(Integer id) {
		return baseMapper.getUserRoleData(id);
	}

	@Override
	public List<UserRoleData> queryAll() {
		return baseMapper.queryAll();
	}

	@Override
	public int updateRolePermission(Integer roleId, String permIds) {
		
		int ret = 0;
		
		if (StringUtils.isNotBlank(permIds)) {
			permIds = StringUtils.trim(permIds);
			// 先删除既有的关联，再添加
			baseMapper.batchDelRolePermission(roleId);
			
			for (String permId : permIds.split(",")) {
				ret += baseMapper.addRolePermission(roleId, Integer.parseInt(permId));
			}

		}
		
		
		return ret;
	}
}
